(function() {
  const originalXHR = window.XMLHttpRequest;

  window.XMLHttpRequest = function() {
    const xhr = new originalXHR();

    // 重写onreadystatechange以捕获响应
    const originalOnReadyStateChange = xhr.onreadystatechange;
    xhr.onreadystatechange = function() {
      if (xhr.readyState === 4) { // 请求完成
        if (xhr.status === 200) {
          console.log('捕获到XHR响应:', xhr.responseText);
          // chrome.runtime.sendMessage({
          //   type: 'xhr_data',
          //   url: xhr.responseURL,
          //   data: xhr.responseText
          // });
        }
      }
      if (originalOnReadyStateChange) {
        originalOnReadyStateChange.apply(xhr, arguments);
      }
    };

    return xhr;
  };
})();